package com.sloera.thread;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author sloera
 * @create 2020/4/25
 */
@Getter
@ToString
@AllArgsConstructor
class User {
    String userName;
    int age;
}

public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User user1 = new User("user1", 22);
        User user2 = new User("user2", 35);
        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(user1);
        System.out.println(atomicReference.compareAndSet(user1, user2) + "\t" + atomicReference.get());
        System.out.println(atomicReference.compareAndSet(user1, user2) + "\t" + atomicReference.get());
    }
}
